i i SY x
LD
a
se
A
_
‘ ll
oo
_
.
Sa
_.
gh SEARS
dah
i
_ _
|
i
i
APPLICATION |
BRIGHT SPARK We discuss the problems
that need to be solved before intelligent
3 robots can be brought to life
HARDWARE
AN EYE FOR DETAIL Your computer
ould soon be reading these very words with 1429
an Oberon Omni-reader
4 We compare the Amstrad
version of Dr LoGo with other
implementations now available
SO FORTH Ourintroductionto
__ FORTH illustrates its similarity to LOGo — both
languages were designed to control devices
_FROMRANDOM ACCESS TO
— RASTER SCANNING A weekly glossary 1440
of computing terms _ |
PROGRAMMING PROJECTS :
ON YOUR MARKS... We provide the |
routines that get our game of Go underway :
| MACHINE CODE :
SERIAL DRAMA A look at the facilities of
the Spectrum Interface 1 serial port of use
to the machine code programmer
- PERFORMANCEPIECEThe completed |
_ MIDI interface can now be used to playa 1 432
farewell symphony - | 2) INSIDE
INDEX A complete index to issues 61 to 72 BACK
_ - COVER PHOTOGRAPHY BY CRISPIN THOMAS ,
played.
the mouse to be available within the user's
computer to be able to read or writ
mainframe computerisfitted. =
2) n music programming, ‘step-time’ means that eac
note and space is programmed separately. ‘Real-tir
performing the piece and recording itasitis
hingivigul
sistaseisese
programming is
cat
3) The Magic Mouse Controller program provides the drivers that
enable the on-screen sprite to be controlled from the mouse. Itis
not an applications program initself, butis providedto enable _
sown
ie
ietaitto
a
ent
As we have seen so far in our Series on
artificial intelligence, there is no shortage of
theories and ideas of what robots should,
and possibly will, do. But the actual
problems besetting the development of
intelligent robots are many and varied. We
focus our attention here on the gap between
theory and fact.
In no other field of computing is the gap between
fact and fantasy as wide as in the area of robotics.
The science-fiction robots of Hollywood are
capable of walking, talking and plotting the
overthrow of humanity. Up the coast from
Hollywood, however, at Stanford University, the
latest research robots can scarcely blunder through
a crowded room without knocking over the
furniture.
Of course, robots have productive roles to play
in car factories and elsewhere in industry. But such
systems, typically for paint-spraying or arc-
Cybernetic Starlet
Practical robots are considered to be a modern
development, but Rosa Bosom (Radio-Operated
Simulated Actress Battery Or Stand-by Operated
Mains) pictured here with her inventor, Bruce Lacey,
was built in 1966 to play the Queen of France ina
production of The Three Musketeers at the Royal
Court Theatre, London. Constructed from
government surplus relays and motors, Rosa
accepts commands in the form of musical tones,
which are converted into movement, and is also
equipped with ultrasonic sensors to detect and avoid
obstacles. In her career as an actress, Rosa mimed
her words to taped speech, whileherlios were
moved by remote control. More interestingly, from a
cybernetics point of view, Rosa can interact with a
second robot called Mate.
Rosa has appeared in several exhibitions,
including Cybernetics Serendipity at the ICA, and
more recently she won Andrew Logan's Alternative
Miss World contest in London
THE HOME COMPUTER ADVANCED COURSE 1421
ROBYN BEECHE
Not The Real World
The ‘Blocks World’ is a highly
abstracted model of the real
world that enables Al scientists
to evaluate different methods of
-scene analysis, text
understanding and problem
solving. However, translating
successful Blocks World.
methods to the real world can be
difficult
welding, merely repeat sequences of pre-
programmed operations without variation. They
are so ‘dumb’ that if there is a break in the
conveyor belt bringing work to them, they will
blindly spray or weld the empty air.
The reasons for this gaping disparity between
PR and performance are complex; but they can be
summed up in two words: ‘perception’ and
‘planning’. In the first place, today’s robots cannot
make ‘sense’ of their sensors. In the second place,
they would not know what to do if they could. This
is why robotics is such a good testing ground for AI
theories. ~... :
Robotics draws on all the facets of. artificial
intelligence because its aim is to produce an
artefact that can cope with the real world.
Therefore, a robot must make sense of its
surroundings.
It is not too difficult to hitch up a computer to a
variety of input devices — television cameras, heat
sensors, ultrasound scanners, pressure pads, and
so on — which may well give it access to
information that humans cannot obtain directly,
such as infra-red or ultraviolet light. But unless the
robot inhabits a very tightly controlled
environment, it will not understand what its
sensors signify. Human perception, as we saw in
the instalment dealing with computer vision (see
page 1381), isan ongoing process of psychological
modelling based on what is happening in the real
world.
Itis one thing to devise an efficient algorithm for
finding a route through a maze held in a
computer's memory and displayed on a screen. It
is quite another matter to use that algorithm to
steer a robot around an urban environment —
1422 THE HOME COMPUTER ADVANCED COURSE
where there may be push-chairs, discarded beer
cans, bits of overgrown hedge and other
unsuspected obstacles in the way.
In the real world, Murphy’s Law reigns
supreme. This is the reason why Micromouse
contests (see page 721) are so popular. In these
competitions, a computer-controlled ‘mouse’ has
to navigate to the centre of a complex table-top
maze. Methods for doing so have been known for
many years, at least in theory. In practice,
however, the walls are never quite straight, there
are slippery patches where previous contestants
have spilled oil, and so on. Under such
circumstances, robustness and adaptability matter
more than algorithmic elegance.
In most other fields of AI, the programmer can
retreat to a ‘microworld’ of his own making, such
as with a chess-playing program that operates in
an abstract environment. An expert system is
concemed with facts, not things. This explains
why AI workers are so fond of the so-called
‘Blocks World’.
THE BLOCKS WORLD
The Blocks World is a simplified schematic
environment containing children’s coloured
building blocks. Not real building blocks, of
course, but formalised representations of those
blocks. It is a favourite haunt of AI scientists,
whose programs can solve problems and
manipulate objects within it without leaving the
comfort of their CPUs.
The roboticist has no such refuge. Robots must
face the vicissitudes of reality as best they can. An
intelligent robot — one that can move around
under its own initiative — must be able to build a
KEVIN JONES
KEVIN JONES
cognitive model of its environment. In addition (to
live up to decades of advance publicity) it ought to
be able to respond to spoken commands. And
since all its responses cannot be thought out in
advance, it would be highly desirable for it to have
some degree of learning ability. That is why there
are really no intelligent robots. Before one can be
built, these AI problems will have to be solved:
e Computer vision.
e Speech understanding.
e Problem-solving in a dynamic environment.
e Machine learning.
and that is a minimal list.
Modern industrial robots tend to be designed
for highly structured environments. Typically, a
robot is nothing more than an arm-like device
under computer control, integrated into an
automated factory or workbench. Its ‘hand’ can
have tools bolted on and a human operator can
‘teach’ it a series of movements that it can repeat
whenever needed. It can memorise but not modify
such action sequences. Very often it operates in a
setting that is so tightly regulated that it needs no
perceptual abilities at all.
Some robots, however, have taken a small step
into the real world. These robots are a little less
dependent on people or other machines providing
them their work. They can, to some degree, go
looking for it. |
The most common way of giving sense to a
robot is through vision. A video camera takes
pictures (of an object the robot is to pick up, for
instance) and passes the image information to the
control computer (this may be a separate
computer from the one controlling the robot's
arm). The computer processes the visual
information supplied — using top-down or
bottom-up methods (see pages 1381 and 1401), or
perhaps a combination of the two — and detects
certain patterns that are important in the context
of the robot’s job. This information is sent to the
computer that controls the arm, where it updates a
symbolic description of its environment already
stored there. The robot now has a picture of the
objects and tools it is working with, and
instructions on what to do.
The great advantage of even limited robot
vision is that the robot can be fed parts in various
orientations, and possibly differently shaped parts
as well. It can recognise the type of part it is dealing
with and the angle at which it has arrived, so it can
handle it in the appropriate way. A completely
‘blind’ robot would try to pick up each item in the
same manner, probably with disastrous results.
Another way of making robots more ‘sensitive’
is through touch. Engineers can attach force-
sensors or pressure-pads to the end of the robot's
hand. When these come in contact with some
object, information is relayed back to the
controlling computer. If the robot bangs against a
wall; the force-sensor will send back information
so that it can modify its arm trajectory to avoid
repeating the mishap. The standard promotional
Conveying The idea
A seeing robot may be used to
recognise and pick out certain
items from a conveyor belt. In
this case the robot may need
two computers — one to
interpret incoming data from the
television camera, and another
to control the grab mechanism
THE HOME COMPUTER ADVANCED COURSE 1423
PRESSURE PAD
\ (SENSOR)
4
| Feedback Cycle
| COMPUTER
(CONTROALER)
a)
, INTERFACE)
STEPPER MOTOR
IN JOINT
display for touch-sensitive robots is to have it first
drill a hole in a piece of milled steel and then
perform the same trick using an egg — without
cracking the shell.
Both vision and touch, though at primitive
states of development in current robots,
demonstrate the importance of feedback.
Providing robots with feedback capabilities is
essential if they are to become useful in a variety of
situations. Of course, it is very difficult to
transform information about the outside world
into a form that the robot’s computer can use to
guide its actions. One problem, among many, is
transforming the data in ‘real-time’ (fast enough
for the robot to respond to what is happening
before the perceived event has ended). The small
minority of robots that have been equipped with —
sensory devices and some ability to interpret the
feedback are known as ‘second generation’ robots.
In the instalment dealing with natural language
(see page 1361), we saw that continuous speech
understanding was the hardest of the four types of
language-processing problems. The main
difficulty is that the robot has no control over what
is being said to it.
Nevertheless, it is possible to give a robot a
useful degree of speech recognition (as opposed to
speech understanding). This just means that the
1424 THE HOME COMPUTER ADVANCED COURSE
GRIPPER IN ROBOT'S
HAND (REAL |
WORLD
robot can be trained to respond to a small number
of words and phrases in the appropriate way. It has.
less understanding of what is being said than a dog
that can ‘sit’, ‘heel’ or ‘fetch’; but in a factory where
the human workers may have their hands busy,
even such simple linguistic abilities can prove
worthwhile. | _ |
Some of the most interesting developments in
robotics have arisen from space exploration.
_ NASA engineers have designed a Mars Rover, a
_ robotic vehicle that can trundle around the surface
of the planet Mars. The vehicle will have sensors,
_ such as television cameras, to pick up information
from its surroundings and enough intelligence to
make use of it. It simply cannot afford to await
signals from Earth before deciding what to do
next, since radio messages may take as much as
half an hour to make the round trip. The Mars
Rover is planned for the future, but in 1976 the
Americans landed two Viking probes on Mars.
They were able to analyse soil samples and the
Martian atmosphere without moment-by-
moment supervision from ‘mission control’.
Putting robots to work in space, instead of
people, saves money. According to the latest
American calculations, keeping a person in space
and bringing that person back alive costs about
$10,000 for one hour! Space robots may be
expensive to develop, but they will be cheaper
than their human equivalents in the long run.
A SELF-REPRODUCTIVE SYSTEM
One exotic possibility for the future is an idea first
put forward by John von Neumann in the late
1940s. A mathematician who laid the theoretical -
foundations for the electronic digital computer,
von Neumann did much other work besides,
including the development of a theory of self-
reproducing automata. He proposed _ that
machines could reproduce by following a simple
set of rules. a |
According to von Neumann’s scheme, a self-
reproductive robotic system needs four
components. The first is an automated factory that
gathers raw materials and turns them into
products according to the given instructions. The
second component is a duplicator that copies
these instructions. The third is a controller that
passes the instructions to the duplicator for
copying. The fourth and final part is the set of
instructions themselves, which tells the system
how to construct a complete new automatic
factory out of the products it has made.
These were just theoretical concepts for almost
40 years, until NASA researchers proposed an
engineering blueprint for a self-replicating system
on the moon. Such a space factory would contain a
‘universal constructor’ that would take parts
fabricated by the production unit and build a new
factory with them — including, of course, another
universal constructor. It would make use of the
raw materials on the moon and would not require
servicing from Earth. It could also provide itself
with a steady supply of new robot workers.
ON YOUR MARKS...
Basins outlined the general rules of Go a
provided listings for the game’s I/O
routines, we now need only add a few
remaining miscellaneous routines that will
allow us to play the game proper. These
include the stack data structure and the
useful implementation of recursion
When writing a program of this type, a few
generally useful routines will usually be needed.
These include procedures to update the board,
check for the legality of moves and so on. For
instance, in a chess-playing program, a routine to
check whether or not the king is being attacked
would be very useful.
Of course, we could write a routine to find
moves that place the opponent’s king into check
and, when defending, positions that keep our king
out of check. However, it makes far more sense to
have a general routine that assigns a TRUE or FALSE
value to ‘is the king of COLour in check?’. We can
then call the routine with different values of
COLour, and then decide what to do with the result.
We are going to adopt a similar approach with
our Go program. Rather than having specific
routines to decide what to do with various types of
groups, we'll implement a general routine to count
the members of any particular group. We can then
decide, in the separate calling routines, what
significance the results have.
The main procedure that will do this is called
PROCsearch in the BBC Micro version. It is passed
two parameters: the position of any stone in the
group we wish to count (P%); and the colour of the
group of stones (C%). The procedure then adds1 to
CSTN%, which is used to total the number of stones
in the group, and looks at the four adjacent stones.
For each of these adjacent stones, it then carries
out the same procedure, but only if the stone hasn't
already been counted. Of course, we already have
a procedure to carry out this search in four
directions from a given stone, so the obvious way
to count the adjacent stones is for the procedure to
call itself! This is an example of recursion, and may
seem rather complicated at first. To make things a
little clearer, here is a structured breakdown of the
search routine:
SEARCH (from-position, for-colour)
|F from-position is on the board
AND from-position contains a stone of for-colour
AND we have not already counted from-position
THEN
mark from-position, so we don’t recount it
add one to CSTN% (our count variable)
SEARCH (north of from-position, for-colour)
SEARCH (east of from-position, for-colour)
SEARCH (south of from-position, for-colour)
SEARCH (west of from-position, for-colour)
ENDIF
END SEARCH
Note that the recursive calls are dealt with as four
separate statements, rather then in a loop to avoid
problems when the recursion is deep.
THE STACK STRUCTURE
When the routine calls itself, the “from-position’
parameter is replaced by the new from-position
(in one of the four directions) and the routine
continues. The new from-position may also call
the search routine recursively, creating yet another
from-position variable, and so on. At some point,
one of the IF conditions will be false, so the
particular call will terminate without the THEN
statements making a recursive call. Whenever the
recursion “backs up’ a level like this, the previous
value of from-position will be restored.
This ‘stack’ data structure can be thought of asa
pile of plates. When the routine is called
recursively, a new plate will be added onto the top
of the stack. However, when this particular level of
recursion terminates, this same plate must be
taken off the stack (and the same variable value
will be restored). This is known as a LIFO (Last In
First Out, see page 948) structure.
Unfortunately, though BBC Basic supports
recursion through PROCedure parameter passing
and localised variables, the Commodore 64,
Sinclair Spectrum and Amstrad CPC 464/664 do
not have this facility. Consequently, in these
routines, you'll find the arrays called SK%() or s(),
which stack the necessary values.
This is done by holding a pointer ( STACKS or
THE HOME COMPUTER ADVANCED COURSE 1425
Counting
Heads
The search routine, which is
used to evaluate the status of
groups on the board,
~ incorporates (or simulates)
recursive procedures to search
in all four directions from |
every stoneinthe group. The |
routine terminates whena —|
liberty or an enemy stone is
reached
PROGRAMMING PROJECTS/GO
equivalent), which keeps a record of the topmost
position of the stack. Every time something is
placed on the stack, this pointer is incremented,
and whenever something is removed, the pointer
is decremented. The appropriate variable is then
reset with the value at the top of the stack.
A by-product of this search routine is that the
recursion always terminates at the edges of the
group it is looking at. When we reach these edges,
we can check whether they are at the edge of the
board or contain a stone of the opposite colour. If
neither of these conditions is true, then it must be a
liberty of the group. Consequently, the second
part of this routine counts the number of liberties
associated with the group, using the variable
CLIB%. Again, these positions must be marked
once they have been counted, or it would be
possible to count them twice.
When counting a group of stones, we will
always call the routine PROCcount, which in turn
calls PROCsearch. This will initialise the count
variables, and clear the markers after using the
search routine.
When marking positions, you'll notice that we
use the actual board itself, to avoid double-
counting. (This is illustrated on page 1395.)
Having marked the board, however, we have to be
able to remove the markers before continuing.
Again, we've used a general routine, PROCclear,
which logically ANDs the appropriate board bytes
with 3, which removes the marker in bit 2. Since the
colours are contained in the least significant two
bits of each board byte, and the stone and liberty
markers are held in the third and fourth bits, the
call PROCclear(3) is ideal. For example:
Byte: ABCDEFG-H
Mask; 00000:;01 1
Result 0 00000GH
The Spectrum version looks a little different,
because the AND command in Spectrum Basic
does not mask off bits we are uninterested in. It can
only be used to give true/false results in
expressions such as: IF X<3 AND Y=3 THEN. . . We
therefore have to use a normal arithmetic
subtraction operation to clear bit 2 in the
Spectrum version of this routine.
By defining this general clear routine, we can
_ also use it to clear the board before a game, by
calling the routine with a zero parameter. This has
been added in line 1400.
There is only one game procedure remaining
before we can start writing the actual routines to
process moves. This is the code that sets up the
board at the beginning of the game with the
appropriate handicap stones. As explained in the
first instalment of this series (see page 1366), Go
has a unique method of balancing skill levels by
allowing the weaker player (who always takes
Black) to place between two and nine stones on
the board as the first move. These stones must be
placed in specific positions, which are set up in the
read handicaps routine (lines 600 to 750). If you ran
the first part of the program given previously you'll
1426 THE HOME COMPUTER ADVANCED COURSE
have noticed that you were prompted to enter a
handicap number at the end of the title_screen
routine (but at the time the number was ignored).
By adding line 1580 and the routine from lines
1630 to 1690, the handicap stones will now be
correctly placed; the DATA statements between
lines 670 and 740 give the correct board positions,
with each statement corresponding to a number of
handicap stones between two and seven. —
In the next instalment we'll add the routines
GO/PROGRAMMING PROJECTS
900000
oo
required to allow you to play the game proper.
Due to the structured way in which the program
has been developed, we'll also be able to easily
modify the program to allow two-player games,
with the computer checking that nobody cheats.
THE HOME COMPUTER ADVANCED COURSE 1427
00 000000
ameaee
ee
a>
Cc
= =
2828
sf2nec
rab) < ¢
=o: oO Nn a.
So eesses = oO
Ssosert 2 oc Ss . e
=a oe i a.25 os
Se2uess Seneee= :
Secsves SEscx oo = =
zOaf os iy Seno eS ors
22s a = = = = © =Socot
EeSeseso 2 a° See =
= 2 = aa Ss = oes % Be
Bo oe5 Ses Pos cha =
BSB ee > >> @ecet =m Y z
SESE ES Soc © 5 8
SBSEES ~~ S > = == Zz
ESos ~O > =
SHe%5ss a
Bes52S2 > a
CO © (ce
=
(a)
senate
1428 TH
E HO
ME COMPUTER ADVAN
CED CO
URSE
The Oberon Omni-reader is the
recognition (OCR) device ]
both reliable and within fae
range of small to medium-sj
-sized
businesses. Text from a printed
Page can be read by the Omni-
reader and transferred directly
RS2
Enables the text to be edi
| edited on
screen without having to type in
the entire document. At present
Oberon has provided software
business micros although any
-RS2
Read All About it
first optical character
the price -
into a COmputer’s wo
| rd
processing Software via an
32C serial interface. This
only for the most popular
Computer with a Suitable
32C-compatible interface
Can use the system
Alth e
1955, optical character recognition (OCR)
devices have only recently become practical
and reliable. The Omni-reader, from
Oberon International, is one of the newer
microprocessor-based OCR’s, which can
read printed text into a microcomputer
speculation about the concept and development
of the ‘paperless office’. The idea stems from the
fact that since data can be directly transferred from
one computer to another, there is theoretically no
need for the information to be on paper. However,
the predictions concerning this ideal situation
have proved to be somewhat premature. Most of
us still find using pen and paper the most
convenient method of noting down information.
Also, data still has to be typed manually into the
computer during the ‘transitional’ phase between
today’s office and the ‘paperless office’. To speed
up this process, optical character recognition
(OCR) devices, which first appeared in 1955, read
text from a printed page into a computer.
However, they have only recently become reliable
and practical propositions for business use.
The Omni-reader from Oberon International is
one of the newer microprocessor-based OCRs
appearing for business micros. Although the
software is initially available only for such
machines as the IBM PC and its compatibles, the
Apricot range and the Apple Macintosh, it’s
conceivable to use the device with any micro fitted
with a suitable RS232C interface.
The Omni-reader consists of a_ plastic
document tablet with a horizontal rule that slides
along a vertical bar on the left side of the tablet.
The optical reader itself (a hand-held device with
two buttons and an LED on top) is mounted on
the rule and may therefore be moved to and fro
across a document laid on the tablet, in very much
the same manner as with an xy plotter.
A number of different functions and typefaces
can be selected, which are flagged by LEDs along
the top of the tablet. There are only four typefaces,
or ‘founts’, which the Omni-reader can currently
scan. These are Courier 10, Courier 12, Letter
Gothic 12 and Prestige Elite 12, which are the four
‘most popular founts used by daisywheel printers
and electronic typewriters.
Inside the optical reader are two infra-red light
sources on either side of a lens that focuses the
image on the light detector circuitry. The detector
can only read characters typed with carbon-based
inks or photocopier toner (most of which is also
carbon-based), creating some advantages and
disadvantages. On the positive side, it means that
ink from ballpomt pens and other non-carbon-
based inks are ‘transparent’ to the detector. Thus
appropriate text can still be read even though it —
THE HOME COMPUTER ADVANCED COURSE 1429
CRISPIN THOMAS
may have been marked with a pen or a rubber
stamp. Furthermore, it also means that most
coloured papers will not affect the operation of the
Omni-reader. However, the sytem’s design
limitations are evident in that pencil marks will
have to be completely erased if the text is to be
read properly.
Attached to the optical reader is a cable that
slots into the back of the Omni-reader tablet. Also
along the back are the external power supply
socket, a standard 25-pin RS232C D socket and
two sets of DIP switches — one to set the baud rate
aid another that offers functions such as
‘handshaking’ and character spacing.
Command Performance
These are commands that can ,
be read by the Omni-reader. 4
Note the two squares before |
the commands. This tells the
Omni-reader that what follows
is acommand and should not
be printed
The Ruling Part... ml
The rule allows the line of text
to be positioned accurately
within the scanning window.
Note the coded strip at the
bottom of the window to tell
the OCR which way it is
scanning
To read text into a computer, you first place the
‘hard copy’ onto the tablet, and then align a
window, cut into the rule, over the line of text that
is to be read. The button on the optical reader is
pressed and the unit is moved along the rule,
thereby scanning the text through the window.
After about a second or so, if the Omni-reader has
successfully read the line, the LED will flash once,
a single beep will sound, and the line will appear
on screen. If the reader has not read the line
correctly, it will flash and beep twice. ‘The user can
then choose either to re-submit the line by making
another pass across the screen (pressing the lower
button and trying again), or tell the computer to
accept the line by pressing the top button.
The Omni-reader compares the pattern that it
reads with the list of characters it has for that
particular typeface. The fount characters are held
as bit-mapped templates within the Omni-reader’s
memory and the unit picks up characters by
constantly scanning the image focussed through
the lens. This image is then divided into 50 ‘slices’,
1430 THE HOME COMPUTER ADVANCED COURSE
STRENGTHS
WEAKNESSES _
Visual Guidance
The optical character reader is
guided across the line of text
by hand. At the end of a line,
the LED on top will flash. One
flash indicates a correct
reading while two warns that
the effort was not completely
successful. A continuous light
means that the device has
failed to read the entire line
| A A, A = KE) Q O Q
: 44. 24% $$
TEST SHEET
THE OMNI-READER
ary new Text Reader or
er.
the price of your ¢o
an jump from the
ate be li ss 2 te
in both horizontal and vertical directions.
As it moves across the line of text, the Omni-
reader is looking for entire characters underneath
the head. It will only process a character that is
both in the centre of its field of view and not cut by
any of the boundaries of the area being scanned.
(This is the reason why the character is scanned
both vertically and horizontally.) The character is
then sent to be matched with the characters in the
device’s memory.
When the Omni-reader finds a match, the
software will then send the equivalent ASCII code
to the computer via the RS232C interface and the
character will apprear on the screen. Because the
Omni-reader has to be able to find an exact match
with the template held in memory, the text has to
_be aligned correctly within the scanning window.
Therefore, if the descenders (letters like y, g, p and
q, which have parts of the character below the
‘line’) are outside the window, they might be
mistaken for something else — for example, a p
might be mistaken for an o.
Alternatively, if the window is too far down, the
optical scanner might pick up the tops of the
characters on the line below and try to interpret
them as well. Problems will also arise if the user
tries to input text that is either too large or too
small to fit comfortably within the scanning area.
Oberon recommends that only 10 or 12-point
characters (four of five characters per centimetre)
be used. Anything outside this range is liable to
generate an unacceptable level of error.
Within these restrictions, the Omni-reader in
fact works surprisingly well. The optimum scan
time for an A4 line of text is between 0.5 and 1.5
seconds, which is about how long it takes tomakea
smooth slide across the line. Although the novice ©
user might have some initial difficulty lining the
text correctly, it does not take very long to be able
to judge the spacing; within half an hour you
should be consistently producing error-free lines.
‘OPTIONS AND COMMANDS
In order to assist you in trying to read poorer
quality typefaces, some options have been added.
These options are fed into the Omni-reader by
passing the optical reader over written commands
— four of these are placed at the top of the tablet
and the rest are listed in the manual. Each -
command requires two solid squares to precede it
so that it is read as such, and not as a word to be
displayed on screen.
Of the four commands that are set on the tablet,
the most commonly used will be TYPEFACE, which
enables you to choose the fount that will be read.
NUMERIC removes the alphabetic characters from
the fount and will only read numbers, thus
speeding up the reading process. This option is
perhaps one of the most useful applications of the
Omni-reader since it is when copying figures that
most undetected errors are usually made.
Direct input is a neat method of avoiding this
problem. To deal with poorer quality printing, the
option POORCOPY can be utilised, which slows
down the read rate of the Omni-reader so that it
can obtain a clearer image of the character under
the optical reader. It is particularly useful when >
reading type generated from cloth ribbon systems
where the carbon is less dense.
The Omni-reader software consists of a pair of
driver programs that reside in the system area of
memory. This means that applications programs
can be loaded into the computer at the same time.
Therefore, data read from a piece of paper can be
input directly into a word processing program such
as WordStar or, if you are reading in figures, can be
read directly into the columns of a spreadsheet for
instant calculations. —
The price of the Omni-reader is £914, including
software and a connecting cable to the computer
of your choice. Also included is half a day’s
training and free on-site maintenance for a year.
By any standard this is not particularly
inexpensive. However, for a business that receives
a lot of typewritten copy, such as a newspaper
office, investing in an Omni-reader will definitely
be cheaper in the long run than employing a full-
time copy-typist. |
THE HOME COMPUTER ADVANCED COURSE 1431 _
yn ee
PERFORMANCE
PIECE
We conclude our MIDI interface series by
considering further the techniques involved
in writing MIDI software. Also, we include
as Assembly language program that enables
the BBC Micro to act as a digital recorder
and playback device.
In the previous instalment, we examined the
differences between normal analogue tape
recording and the recording of digital MIDI data.
We saw how these differences can be exploited to
minimise the use of computer memory by using
timing messages.
The digital recording and playback application
provides us with a good example of some common
problems we will often encounter when
programming for MIDI. The program has to be
able to receive and transmit MIDI data via the
hardware interface designed earlier (see pages
1343 and 1368) and, moreover, this data must be
received and transmitted in real-time. In other
words, the program must run fast enough to
accept, process and store one MIDI message
before the next message arrives.
In addition, because we are recording in real-
time, we must have some reliable timing source
within the computer that will synchronise the
program’s actions in record and playback modes,
and also record timing bytes within the memory
array used to store the recorded sequence.
Most applications which require regular
updating are interrupt-driven — that is to say, they
use the IRQ interrupt signals to regularly execute
particular sections of program code. However, for
this application, the interval between successive
IRQs may well be longer that the time between two
successive MIDI messages. When the program is
in record mode, this could prove disastrous, as
whole MIDI messages could be missed, producing
very odd effects when the piece is replayed. For
example, if a ‘note off’ message was missed during
the recording phase, that note, once triggered,
would play on endlessly. We must therefore
disable IRQ interrupts and seek another timing
source for our program.
MIDI TIMING
The I/O chips used by the Commodore 64 and
BBC Micro are similar and each has an on-board
16-bit timer register, which can be directly
programmed to count down from a preset value to
zero. On reaching zero, an interrupt flag is set and
the timer is reloaded with its initial value. When
operating in this way, the timer is said to be
operating in “free-run mode’.
1432 THE HOME COMPUTER ADVANCED COURSE
The program uses this timer as follows: the
subroutine check checks to see if the timer has
‘timed-out’ by interrogating the CIA/VIA chip’s
IRQ flag register and sets the Z flag in the processor
status register accordingly. The recording and
playback sections of the program both call the
check subroutine and use BNE or BEQ instructions
on return from the routine, branching according to
the state of the Z flag. |
The check routine also scans the keyboard to see
if the Space bar has been pressed to stop the
sequence. On the Commodore 64, this check is
peformed, in the absence of the normal IRQ-driven
keyboard scan, by checking the last row of keys on
the keyboard. ‘The BBC Micro version checks the
keyboard via OSBYTE call &79. As long as we
ensure that the check routine is called at least once
between successive time-outs, this will provide us
with a reliable method of timing the reception and
transmission of MIDI messages
SYSTEM MESSAGES
It is not necessary, or even desirable, to record
every message sent on MIDI. Since the Recorder/
Playback program generates its own timing,
system real-time messages are irrelevant and must
be ignored if received. (Most keyboard
instruments will be incapable of transmitting these
codes unless they have a built-in sequencer.)
System common and _ system exclusive
messages may be inadvertently transmitted and
must also be ignored. However, these messages
may consist of any number of bytes and so a flag
must be used to instruct the recorder to ignore all
data until reception of a channel status byte
occurs. This is indicated by a value of SFF in the X
register. Other values held in the X register act as
counters representing the number of data bytes to
be received before the current channel message is
complete.
Mg ne
a
770 .pio . : 1610 STA (mem) ,Y
1620 .c20
K* BBC MIDI PROJECT xx
** DIGITAL RECORDING «x
**% AND PLAYBACK x
1670 LDA timertis
1680 AND #&40
1690 STA timer+13
1700 RTS .
1710 .store
1720 STA (mem) ,Y
INC freemem
stregq=&FEEO
80 datreg=stregtl
70 mem=&70
100 ptr=&72
110 PH=start
i2o [
JSR strout
JMP c20
read
1840 LDA (mem) ,Y
OPT opt
LDA #1
JSR strout
STY clocks
»rO0s
LDX #&FF
rid
JSR check
BEQ r20
220 STA streg
230 LDA #&16
240 STA streg
290 .gifd
260 LDA #&FF
STA lowmem
BCC nid
CMP #&E0
BCS ni0
DEX
STY clocks i770 .nid
»Fr20 1980 STX nobytes
LDA streg
AND #1
CPX #1
350 LDA #0
360 JSR strout
370 .Q2i
380 JSR osrdch
390 CMP #ASC"E"
400 BNE 922
2060 LDA messtabtl ,X
2070 STA ptr+l
2080 LDY #0
2090 .mi0
2100 LDA (ptr),yY
2110 JSR osasci
2120 INY
2130 CMP #&0D
2140 BNE mid
300 STA
mess0=P~%
510 LDA $P%="R = ,P = play,E = exit"
520 STA ae ik _— PHA PX=P%+LENC$P%) +1
530 LDA «Hfrbytes MOD..2560 ge LDA.c locks messi=PY
JSR store
STY clocks
PLA
SPA="recording"
PA=PA+LEN( SPA) +1
mess2=Px%
»rso $P2="playback"
JSR store
DEX
600 CMP #ASC"R" 1440 BEG rid
610 PHP BNE r20
620 BEQ rd00
630 .p00
640 LDA #2
650 JSR strout
]
NEXT
?Px~=mess0 MOD 254
PA? 1=messO0 DIV 256
PA? 2=messl
STA clocks
740 CMP #&FO
750 LDA clocks
760 BEG p30 1600 LDA
THE HOME COMPUTER ADVANCED COURSE 1433
yn A oo
ee
As one of the better introductory computer
languages, LOGO has gained a wide appeal in
the educational market as well as with home
- micro users. Here, we look at Dr Loco for
the Amstrad computers and compare it with
the original produced for the IBM PC.
When Loco was first transferred from mainframe
computers to eight-bit microcomputers, a number
of restrictions and simplifications had to be made
so that the language could run within the 64
Kbytes or less of memory that was available. As
16-bit micros began to appear with much larger
memories, a number of enhanced versions of
LOGO quickly became available.
Gary Kildall — the founder of Digital Research
(the producers of the CP/M operating system) —
was excited by LoGo’s potential as a language and
had produced his own version for the IBM PC,
calling it Dr Loco. This version has since been
made available on a number of other 16-bit
machines. The Apricot Fle (see page 1389), for
example, comes supplied with Dr Loco.
Digital Research has since adapted Dr Loco for
a number of eight-bit CP/M machines. Amstrad
is providing such a version of Dr Loco along with
its disk pack for the CPC 464.
Dr Loco, as implemented on the IBM PC,
requires at least 192 Kbytes of memory torun. The
disk is copy-protected, but a backup copy is
provided. To run it, you just insert the disk and
peform a system reset. The colour graphics
resolution is 320 by 200 pixels with a choice of 16
background colours, together with a choice of four
sets of three pen (foreground) colours.
With a colour graphics card on the PC, along
with both a colour and a monochrome screen, Dr
LOGO can produce graphics on the colour screen
and text on the monochrome screen! However, if
ou only have one monitor, the two can be mixed
on the same screen.
Dr LoGois described in the manual as a superset
of Apple Loco and it in fact contains all the Loco
commands to be found there. These include the
standard graphics, list processing and workspace
management commands as well as error handling
primitives, ‘properties’ (a way of assigning more
than one value to an object) and ‘packages’ (a way
of bundling procedures together as a group). Dr
LOGO is ‘case sensitive’ and therefore LOGO
commands must be entered in lower case. 3
The editor makes use of the IBM function Keys
but also recognises the same control codes used in
Apple Loco. If an error is found while running a
program, typing ed will implement the editor with
1434 THE HOME COMPUTER ADVANCED COURSE
the offending procedure in place, ready to edit.
Unfortunately, there is no way of telling by looking
at the screen when you are in the edit mode. Most
other versions of Loco indicate this by having a
special line at the bottom of the screen.
NEW PRIMITIVES |
Besides the usual list processing primitives, Dr
LoGo has a number of new ones:
sort sorts a list into alphabetical order
Shuffle puts the elements of a list in random order
piece enables you to select a part of a list
Dr Loco adds a number of debugging tools:
watch enables you to see the effect of the procedure
line by line :
trace prints out the names of variables as they are
called and as they are defined
debug splits the screen into two windows. The
‘debug’ window can be used to display information
provided by trace and watch, while the ‘program’
window shows the output from the program
Comments can be added to procedures but they
can then be removed from all procedures in the
workspace, with noformat, if this is needed to
provide extra space for running.
There are also a number of new procedure
management primitives:
follows enables you to define the order in which
procedures will be presented on the screen
pot! displays names of procedures not called by any
other procedures
poref <name> displays names of procedures that
call the procedure <name>
pocall <name> displays names of procedures
called by the procedure <name>
What these extra features amount to is an
improved program development environment in
which to create LOGO programs.
There are a number of weaknesses in Dr Loco:
there is no search and replace function in the
editor, no method of interfacing to machine code
and no file handling. The 300-page manual,
however, is very clear and thorough. It has a
tutorial introduction to LOGo as well as a reference
manual that includes a separate page devoted to
each primitive.
Clearly, Dr Loco has a number of attractive
extra features not found in smaller versions of the
language, all of which results in an improved
program development environment.
It is interesting to see how Dr LoGo compares, in
terms of space and speed, with the eight-bit
versions of the language. Loco workspace is
measured in ‘nodes’. Asking Dr Loco how many
nodes it has free on starting the system gives a
comforting answer of around 10,000 (eight-bit
systems typically have from 2,000 to 3,000). So
there is plenty of workspace for defining
procedures and for running recursive procedures.
However, end recursion — the case of a recursive
procedure in which the recursive call is in the last
line — is not implemented efficiently, and so
programs that would run infinitely on
Commodore or BBC machines, run out of space
after a few hundred recursive calls with Dr Loco.
As far as speed is concerned, the graphics are
fast, but arithmetic and list processing are both
performed more slowly than with other eight-bit
versions of the language.
THE AMSTRAD VERSION
Dr Loco is supplied with the Amstrad disk drive
(see page 1209), and is on the opposite side of the
CP/M disk. Dr Loco on the Amstrad is modified
to take advantage of the hardware it is running on.
The graphics use the same four-pen system as on
the Dr Loco for the IBM PC, but the pen colours
are now set by giving a list of numbers determining
the proportions of red, green and blue required.
The IBM version does not have an extensive range
of sound commands, whereas the Amstrad
version has env (for volume envelope), ent (for
tone envelope) and release, which releases
channels set to a hold state in a sound command.
The Amstrad version has most of the features of
Apple Loco — including properties and error
handling, but not packages. |
The debugging primitives and the extra
procedure management features of Dr LoGo on
the IBM PC have been left out, presumably
because of the smaller memory capacity of the
Amstrad. More serious, however, is that there is
no define function and seemingly no way of ©
deleting a file without exiting to CP/M and then
coming back in again.
The editor is very slow to respond and you
might find yourself typing ahead and losing the
odd character. On the other hand, if an error is
found in running a procedure, the editor, once
entered, positions the cursor over the offending
word in the procedure, which is a very useful
feature indeed.
The Amstrad version provides limited access to -
machine code via .examine and .deposit (PEEK and
POKE), which the IBM PC version does not have.
The documentation supplied is minimal, and
you are referred to a tutorial and reference manual
that has yet to be published. In the meantime, you
will have to rely on the 25-page summary of the
commands. Also, there appear to be some
features of Dr Loco that have been implemented
but have not been mentioned.
A lot of the more exciting features of Dr LoGo
for the IBM PC have disappeared in the Amstrad
version, but we are still left with a good standard
implementation of LOGO, with extras such as
packaging and error handling.
On starting up, Dr Loco claims to have 2,105
nodes, which is a typical figure for eight-bit
systems. However, end recursion has not been
efficiently implemented; and for graphics,
arithmetic and list processing, this is one of the
slowest eight-bit LoGos, with most operations
taking about three times as long as on the
Commodore 64.
THE HOME COMPUTER ADVANCED COURSE 1435
0 DEGREES AZIMUTH 90 DEGREES ELEVATION
i In summary, then, you would need:
® Elementary telescope commands.
@ Ways of combining the elementary commands
into more complex ones — telescope ‘programs’.
This system could amount to a complete telescope
Fortu is a programming language that was Programming language. It would, however,
originally developed to control a radio ‘duie an extra, rather special, property: it would
telescope, and it is generally regarded as have to accept commands — both the built-in
| : aa commands like ELEVATION and any new ones —
| Se . sau setae ao aan directly from the keyboard. Additionally, it would
: 3 have to do this in as simple a manner as possible.
looks at FORTHS two key features — Imagine trying to fulfil these requirements in
interactiveness and extendability. | BASIC, which is quite good at letting you use its
built-in commands, like PRINT and RUN, from the
Invented in the late 1960s by astronomer Charles eyboard. Your new commands, however, will be
Moore, FORTH was specifically designed to control 4 Fyoblem. Assuming you have already defined
a scientific device that needed precise positioning. j7|MyTH and ELEVATION as GOSUB routines at lines
The language’ _usetulness extends far beyond 14990 and 1100 you might write a command for
control applications, however, but as an pany ag. Ss
introduction to its basic operating principles, it is
instructive to look at how it can be used to control 1200 REM PARK
a telescope. 1205 LET DEGREES
It would be nice to able to sit down at a 1210 GOSUB 1000
computer terminal in the observatory, and — for 1215 LET DEGREES = 90
example — type in: 1220 GOSUB 1100
30 DEGREES ELEVATION 1225 RETURN
at which point the telescope would move you might be able to predefine a variable PARK
immediately and accurately. It would also be
useful to be able to package and store useful LET PARK = 1200
sequences of such commands to save repetitive
typing. For instance if the parked position has 90°
elevation and 0° azimuth (these are terms
describing the angle and position of the telescope), GOSUB PARK
you could define a new command, PARK, as: The best you are likely to be able to do is define the
GOSUB routine as a procedure (such as in BBC
BASIC) and type something like:
PROCPARK
Thus, whenever you call one of your own
telescope routines, you have to enter additional
commands, like GOSUB or PROC, as well as the
name or line number of your routine.
An alternative is to write an interpreter, a
program that takes telescope commands and
executes them — something like:
100 INPUT CS :
150 IF CS = “PARK” GOSUB 1200: GOTO 100
But then you can no longer type in the BASIC
commands (like PRINT) directly.
il
©
and subsequently issue the command (in some
versions Of BASIC):
An Ace idea
The Jupiter Ace was
attempt to market a m
offering FORTH, rather
BASIC, as the standard
language. Sadly, the Ace's
of colour facilities coupled
a small memory, the
unfamiliarity of FORTH and
strong competition from the
Sinclair Spectrum left it at a
severe disadvantage compared 9
to other home micros. A FORTH S ESSENTIAL
second-hand machine, howeve PROPERTIES
together with the original
documentation (which was of a
very high standard) would
provide an excellent introduction
to the language. The Jupiter Ace
is now being marketed by
Boldfield Computers Ltd,
Cambridge.
We can see now that the two essential properties
for our telescope language will be:
@ First, that it must be interactive. It must be able
to execute your commands as soon as you type
them in. This is like BAsIC, LOGO, APL_ and PROLOG
but unlike PASCAL, ALGOL, FORTRAN and CoBOL. It is
IAN McKINNELL
1436 THE HOME COMPUTER ADVANCED COURSE
also like the command end of operating systems,
such as CP/M and Unix.
® Second, that it must be extendable. The format
for calling commands you've defined yourself
must be identical to that used for the built-in
commands. Then, once you've defined your
routines it will be as though you are using an
extended, more powerful language, rather than
the original language plus some new routines. This
is like LoGo and the operating systems, but unlike
all the other languages.
The concept of extendability is in fact even more
powerful than it has appeared so far. If, for
example, someone sells us a telescope control
language and we extend it in minor ways to
include useful routines for our own telescope, we
will have extended an original ‘general purpose
telescope control language’ to a new ‘personalised
telescope control language. But if the
extendability is to be fully realised, we should be
able to begin with a ‘general purpose extendable
computer language’ and extend that to a ‘general
purpose extendable computer language’ and
extend that to a ‘general purpose telescope control
language’ (indeed, this could be extended to
languages to control robots, _ scientific
experiments, production lines or anything else
that can be connected to a computer).
Furthermore, what is controlled does not have to
be physical. It could be an abstract concept
internal to the computer, like the turtle on a turtle
graphics screen, the records in a filing system or, in
fact, anything you want handled by a program.
FortH is the closest approach we have to a
‘general purpose extendable computer language’.
We have looked at the special problems —
interactiveness and extendability — that it tries to
solve, and in our next instalment we will begin to
look at its solutions.
THE HOME COMPUTER ADVANCED COURSE 1437
MARCUS WILSON-SMITH
<7]
routines for the Spectrum machine code
programmer. We have already taken a
general look at the facilities offered by the
interface (see page 1398); now, we turn our
attention to those hook codes that it uses to
control the RS232 serial port.
ee 8
Let’s begin our discussion with a look at the serial
interface, which is a nine-pin. 270° RS232 socket
(our diagram shows the function of each pin). The
number of these lines that you will need to connect
depends upon the complexity of your application,
and a minimal RS232 link can be established by
using pins 2, 3 and 7. If you do this, pins 4 and 5
should be connected to pin 9 to hold them at logic
one. This prevents the Spectrum from ‘hanging
up’ if whatever is on the other end of the link isn’t
yet ready to receive data from the computer. This
has the disadvantage, however, of losing data if the
other end of the link isn’t able to receive it. It is
better, on the whole, to use the full wiring.
A possible application of the RS232 link is to
connect the Spectrum to a ‘real’ printer. Once the
cable is wired up, the controlling software is simple
to use. To send text to the printer, we set an
appropriate baud rate from Basic using FORMAT,
and then execute the following code:
CLOSE #3
OPEN #3;°T"
This attaches stream 3, which is usually the ZX
printer stream, to channel T, which is the text
channel of the RS232 link. A full discussion of the
use of ‘text’ and ‘binary’ streams is given in the
_ Interface 1 manual. LLIST and LPRINT will now
send data to the device attached to Interface 1.
Now let’s consider the details of the operation of
the serial interface. Data is transmitted with one
start bit, eight data bits and two stops bits. We do
not have to worry about this format, as the
Spectrum operating system routines look after it
for us. What is more important to us is the rate at ~
which data is sent — the baud rate. The baud rate is
usually set up by the FORMAT command, which
restricts us to a certain range of baud rates.
Although there is little loss of data integrity with an
RS232 interface — even over a considerable
distance — it is a good idea to use slower
transmission rates with increasing distances
between sender and receiver.
It is good practice to insert the Interface system
variables using hook code 49 before using any of
the following techniques. There are two hook
codes concerned with RS232, and three system
1438 THE HOME COMPUTER ADVANCED COURSE
variables. Let’s look at the variables first.
@ BAUD (at locations 23747 and 23748) is a two-byte
variable, which holds a value that determines the -
baud rate to be used for the transmission and
reception of data. This presents us with one of the
limiting features of the Spectrum serial interface —
its inability to simultaneously have different baud
rates for send and receive.
@SERFL (at location 23751) is a flag byte, which is
used by the OS on receive only. If it is set to one,
then it indicates that there is still a byte available to
be read. :
SERBYT (at location 23752) acts as a one-byte
input buffer for receive. It is occasionally possible
for a byte to be received and stored in this location
after youve discontinued communication.
Problems can arise with the use of the latter two
variables — we'll look at these later.
A fourth system variable — IOBORD (at location
23750) — is not strictly concerned with the serial
interface, but holds the colour of the screen border
to be used in I/O operations. You can therefore set
it to hold any colour you wish for the screen border
during these operations.
When we want to use the RS2372 interface, then
the first thing to do is to set up a baud rate. This is
done by putting an appropriate value in BAUD —
indeed, this is all that FORMAT does. The value to be
used for a particular baud rate is given by:
value = (3500000/ (26* baud rate))-2
cn ne
CAROLINE CLAYTON
By using this equation, it’s possible to set up the
serial interface with a non-standard baud rate
from machine code, but this is probably of
minimal use unless you are communicating with
another Spectrum via the RS232. The Baud Rate
table gives a variety of baud rate values and the
necessary routine for implementing them.
Now we can consider the way in which data is
transferred across the link. In Basic, the act of
OPENing a stream for use with the RS232 interface
generates a channel of the form shown in the
RS232 Channel Structure diagram. This channel
is placed in the Channel Area of memory. Byte 4
of this channel has 128 added to its value if the
channel has been created implicitly (that is, using
SAVE", MOVE, FORMAT, and so on — see page 1418).
However, this is only of academic interest to us
when we come to use the RS232 routines from
machine code. You will note that there is no buffer
associated with such a channel. We write and read
data by calling up the relevant hook code, which in
turn calls the routine that has its address in either
channel locations 5 and 6 (for transmission) or 7
and 8 (for reception). When we use a hook code,
no channel is set up. The two RS232 hook codes
are:
® Hook Code 29: When called, this returns a single
byte from the serial interface in the A register, if
one is available (in which case, the carry flag will be
set to one). If there isn’t a byte available, then A
will contain zero and the carry flag will be clear.
® Hook Code 30: This transfers the byte in the A
register to the serial interface for transmission at
the current baud rate. When we use this code, all
pytes are transmitted without modification; there
is no difference between the B and T streams at the
machine code level.
It is at this poimt that the problems regarding
SERBYT and SERFL can arise. If the hook code
routine finds that SERFL is set to one, then it will get
a byte from SERBYT, even if that byte has been
‘hiding’ in SERBYT since the last bout of serial
communication was completed. This ‘rogue byte’
needs to be dealt with if it appears at the beginning
of a series of received bytes; all those following will
still be received, but their meanings may now be
altered. ‘The easiest way to get rid of what is in
SERBYT is simply to set SERFL to zero before
attempting to read anything from the serial
interface. This can be done with a simple piece of
code:
XOR-° A |
LD (23751) ,A
That is the only real complication that most people
will find when using the serial interface —
although, should you be unable to get anything at
all out of it, it is always worth swapping the
connections to pins 2 and 3 on the Interface 1 plug,
in case they were wrongly connected in the first
place. The baud rate generated, though not always.
precisely defined, is correct to within the tolerance
required by the RS232 specification.
As an example of using the RS232 interface,
the following piece of code transmits 255 bytes of
data down the serial interface:
isend 200 bytes of data down serial interface
CF rst #8 sset UP.s.
31 . defb 49 je.]/face | variables
216E88 Id hi, it@ value for 1288 Baud
220350 Id (23747) ,h] ‘set baud rate
O4FF ld 6,250 yset counter
3 loop: push bec ;save counter
3E88 Id -a,DATA juser supplies routine..
CF rst #8 ;e..to get data in a reg
1E defb 38 ssend the byte in a
a pop be yrestore counter
16F8 djnz loop
C9 ret
In many ways, the RS232 link is the easiest of the
Interface 1 functions to use. There is no channel
information to worry about from machine code,
and we simply have two calls — transmit and
receive — to deal with.
Means Of Communication
The Interface 1 serial port
provides a means of
communicating with other serial
~ devices and uses a standard
nine-pin D socket. The only
serious drawback of the
Spectrum serial interface is its
inability to use different baud
rates for receive and transmit
—~
5
THE HOME COMPUTER ADVANCED COURSE 1439
- KEVIN JONES
A Nice Little ERNIE
One of the most famous
computerised random number
generators is ERNIE (Electronic
Random Number Indicator
Equipment), which is used by
the Department for National
Savings to select winning
premium bond numbers. In
order to generate true random
numbers, the machine uses
electron diffraction. In this
~ method, a beam of electrons is
passed through a gas, and the
resulting random diffraction of
electrons is used to generate a
number
RANDOM ACCESS
COURTESY OF NATIONAL SAVINGS
Random access refers to a type of memory in
which all the addresses within the system have an
equal access time. Within the semiconductor
memory itself, it refers to ROM and RAM chips,
which both have access times (not including the
address time) of around 0.1 microseconds.
However, random access can also be applied to.
mass storage peripheral devices, such as disk
drives.
Random access on disks requires that there be
some sort of directory listing on the disk to inform
the disk operating system where each component
of the file to be accessed is stored. This is in
contrast to ‘sequential disk access’, which looks at
each of the sectors to see if the file is held there.
The time taken for random access of disk files is
generally between eight and 30 milliseconds. |
RANDOM NUMBER
As its name suggests, a random number is a
number that is generated at random from within
an allowed range. Generating real random
numbers is a notoriously difficult process as
computers, by their very nature, cannot behave
randomly. However, certain machines have been
devised specifically to produce truly random
numbers. These machines generally use the
movement of subatomic particles in order to
generate their numbers — by counting the
intervals between alpha waves (which are emitted
at random) appearing from radioactive sources,
for example, or by the random diffraction of
electrons in a gas sensed by transducers.
Various methods have been devised to generate
such numbers arithmetically. Such methods are
said to generate ‘pseudo-random numbers’,
which, although not truly random (as the sequence
is predictable and cyclic), are nevertheless
indistinguishable from real random numbers in
most applications. 7
To generate random numbers, we first need a
‘seed’ value, which is often taken from the system
clock. From there, we can choose from a variety of
procedures that will produce a series of random
numbers. One of the more common is the ‘middle
square’ method put forward by John von
1440 THE HOME COMPUTER ADVANCED COURSE
Neumann. In this system, numbers are squared
and the middle four digits are used as both a
random number and the seed for the next. —
The problem with this method, as with all
pseudo-random number generating systems, is
that after a while the numbers begin to repeat
themselves or fall to zero. A slightly better
method, in which the cycle length is somewhat
longer, is the ‘middle product’ method. Here, a
pair of seed values will be required, and both are
multiplied together to form a number. The middle
four digits of the result are taken as the random
number. To generate the next number, the first
number is abandoned and the two new seeds are
multiplied together.
To produce really long cycles, however, another
technique is used, called the ‘congruence method’.
This involves placing carefully chosen constants
within a formula, which in the case of the
‘multiplicative congruence’ is:
Xn+1=A/-Xn(MOD B)
where Xn is the current random number, and A and
B are constants. In order to ensure that the cycle
length is as long as possible, X0 (the seed value), A
and B should be chosen with care. X0 should, for
example, have no factors in common with the
modulus B. It is also advisable, when using binary
arithmetic, that B=2™, where W is the number
of bits available (eight on an eight-bit micro). Thus
a good value for B in an eight-bit micro would be
256 (2°).
To further improve the cycle length, the value of
A should correspond to the formula:
A=8P +3
where P should be a positive integer. This
generates relatively prime numbers. For example,
where P=1 the result of A can be either 5 or 11,
whereas if P=2 the value of A can be either 13 or 19.
Apart from their obvious applications in games
programs, random numbers do have ‘serious’
applications. Simulations, in which degrees of
‘randomness’ are required, are often used for such
applications as traffic flow predictions. Another
example is the Monte Carlo method, which
randomly samples a set to gain an idea of the
whole. This is most often used in numerical
analyses.
RASTER SCANNING
Raster scanning is a method of building up a
picture on a VDU screen and is most commonly
used in standard television screens. The electron
sun at the base of the cathode-ray tube draws a
series of lines from the top to the bottom of the
screen, turning on each of the screen’s
electroflourescent points in turn. When the final
line on the screen has been drawn, the gun returns
to the top and ‘refreshes’ the picture.
Raster scanning is used by the computer for a
variety of applications, not only for producing
graphics displays. It is often used by light pens (see
page 969) in order to fix their positions.
_ | ‘a. oo 1207-1208
| MICRO” O-PROLOG 1272- 273,
|_| Microtet 1374-1375
| MIDE interface 1335- 1337, 1343-
- |) Opie boii: circuit 1336
| Osborne 1 1264 ©
1327
1345, 1368-1371, 1386- _
1388, 1412-1414, 1432.
| indlink 1201-1203
| Minimaxing 1269- 1270, 1281
| Mobile Robot program 1353
| Mood-sensing software 1203
_| Moore, Charles 1436
_MP/M 1347
_ Mycin program 1 1222- 1223, 1302-
a
_ Natural language processing 1361- |
| oa
_ -| Natural Language program 1364
__| Neuralnets 1221 :
Lo World game 1214, 1232, -
1267, 1295
full listing 1314- 1316,
1338-1339, 1354-1356 ,
. Noe andcrosses1269
Game 1270- 271, SS
| Oberon Omni-reader 1429- 1431
| Octuples 1403 -
_ ae systems 1218- 1219,
| 1237-1240, 1256-1259,
| 1276-1279, 1296-1299,
«1317-1319, 1332-1334,
| 1357-1359, 1378-1380, |
- 1398-1399, 1418-1420, |
1438-1439 |
Output device 1215
3 Overflow y 1215
| Pecng 1215
| Page 1215
_| Page printer 1215.
| Papertape1228 CC .
| Parallel input/ output 1228
| Parallel processing 1228 ©
| Fegace oe
. Parity 1252 _
_ | PASCAL 1204-1206, 1234-1236,
| Pass 1252
_| Password 1280
_| Patch 1280 a =—i—Or—s—s_heSMm
| Pattern Recogniser program 0 1402- .
2;
_ | Radix 1409
_ / | RAM 1409
| Random access 1440 ©
_ | Random number 1440
__| Raster scanning 1440
| RM Nimbus 1328- 1331
| Rosenblatt’s Perceptron 1221-1223 | ltee
_ Rotating (be poze 1258- -12: 9, | Tree
| Pearl, Judea 1281
_| Pen 1207- 1208.
| Penform 1207 CC
| Perfect suite 1230- 231
-Peripheral1289 CSOs
| Peripheral interface adaptor 1289
_ | Permutation 1289
__—s| é6Personal a 1289
__| PET 1308 _
| PIA 1289 ___ _ |
| Picture processing 1308, B81 [—hUd|T ]|))—hUCrhrFhre
| Picturesque I Editor/ Assembler | S 7. _.
| Samuel, Arthur 1269
| Scout algorithm 1281
Plasma display 1308 |. _.
Searching 1241-1243, 1268- 27,
| Platform a 1220
_ Ply 1282
| Pointers 1234- 38
| POKE 1340
- Polish notation 1340
Polynomial 1340
_ Port 1340 © _—=sSOSsSCS
| Postfix notation 1340 |
| Predicate logic 1272 ©
| Printed circuit 1340
Query ieee 1409 _. _
_ Olieve 1409
1246-1248, 125 -
‘(1403
Ponce oo 1280, 1381,
«1401- 1403
1383 ©
1298
Plotter 1308
Printer 1360
Probability 1360 - —ese
Procedure1360 i ets
| Program 1365
| Program counter 1365 |
Program development oon 1365 |
Program generators 1374-1375, |
1396-1397
| | PROLOG 1272-1273, 1292- 1293, 7 . _
1312-1313, 1326-1327,
265 °
| PROM 1365
| PROM — 1365
| Prompti392 ~—es
| Protocol 1392
|Pulse1392
Punched card ‘i392 _
oe data drive 1372-1373
Quick operating system oe _
| Ovickson 1409
- / | = ull 1374- 1375
1372-1373 ©
‘(1277-1279 ©
_ Rule breeding syst ems 1321-1323 |
1281-1283, 1312-1313
|. SelE-leaming systems 1321-1323
| Self-reproducing automata 1424
| Serial input/output 1228
| Serial port 1438- “
| Shadowfire 1320
____| Shannon, Claude 1268
__| SID chip 1237-1238 |
| Since Spectrum —
___-Hi-Res Pees 1334
Go game 1408, 1428
_ i _ memory map 1296
Numbers game 1283
_ operating system 1296- 1299,
1317-1319, 1332-1334,
1357-1359, 1378-1380,
1398-1399, 1418- 1400, _
- 1438-1439
printers 1262- 1263 —
“robotarm sequence — _
programmer 1216-1217
serial port 1438-1439
simulation game 1212-1214,
1232-1233, 1244-1245,
1266-1267, 1294-1295,
- 1314-1316, 1338- 1339,
_ 1354-1356 _
_tape control 1357- 1359
| SOL System 1264
___| Speech recognition 1280
| Star networks 1386
| Streams 1332-1334
| Suicide 1366-1367
oe 1404- 140
| Super suite 1390-1391 _
| Sycero 1374-1375, 1396-
. — 1388 _
‘VICI “se 1218-1219
von Neumann, Joba 1268
lw)
_ Wheat Counsellor 1303
| Wiener, Norbert 1221- 1222
Wildcard characters 1305
| Wirth, Niklaus 1246, 1252 |.
WISARD 1382, 1401- .
1403
| WordStar 1265 -.
| Workshop ae tracer 1253 | :
GC 1255, 1274-1275, 1286- |.
1288, 1306-1307
| | Workshop MIDI interface 1335- _ _
- 1337, 1343-1345, 1368- Se
1371, 1386-1388, 1412- |
1414, 1432-1433
| Workshop robot arm 1216-1217, i _
a 1227
aes
_| Zero page 1215 -
ZX ee 1261- 1263